Skip to content

random: Make php_random_bytes() useable early during engine startup #14291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2024

Conversation

arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented May 21, 2024

php_random_bytes() uses some thread-specific state and can not be used too early. In this PR I refactor it so that is uses a true global instead.

I also introduce php_random_bytes_ex(), with a slightly different API that can expose errors without throwing exceptions.

This is a dependency of #14054.

@arnaud-lb arnaud-lb marked this pull request as ready for review May 21, 2024 17:35
@iluuu1994 iluuu1994 removed their request for review May 21, 2024 22:58
Copy link
Contributor

@zeriyoshi zeriyoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a Windows test environment so I can't verify it at hand, but the code is clear and fine and the CI test cases seem to cover the relevant areas.

This variant can be used before RANDOM_G() is initialized
@arnaud-lb arnaud-lb force-pushed the get-random-atomic branch from d03040d to 3874016 Compare May 30, 2024 10:54
Copy link
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now, thank you. Sorry for the incremental change requests from my side!

@TimWolla TimWolla changed the title Make php_random_bytes() useable early during engine startup random: Make php_random_bytes() useable early during engine startup May 30, 2024
@arnaud-lb arnaud-lb merged commit 44c199c into php:master May 30, 2024
11 checks passed
@arnaud-lb
Copy link
Member Author

Thank you @morrisonlevi @TimWolla @zeriyoshi !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants